<template>

    <mi-list-page>

        <mi-table :list="list">
            <template #topBar>
                <mi-top-bar
                    :data="topToolbar"
                >
                </mi-top-bar>
            </template>

        </mi-table>

    </mi-list-page>

    <goods-tag-edit />

</template>

<script setup lang="ts">

import {getCurrentInstance, onBeforeMount, onUpdated, provide, reactive, ref} from "vue"
import {makeModelAuth} from "@/utils/auth";
import global from "@/dict/global";
import {useRoute} from "vue-router";
import List from "@/model/list";
import Edit from "@/model/edit";
import {simpleGet, simplePost} from "@/utils/request";
import {FormInstance} from "element-plus";
import Search from "@/model/search";
import GoodsEdit from "@/views/store/goodsEdit.vue";
import GoodsTagEdit from "@/views/store/goodsTagEdit.vue";

const route = useRoute()
const restoreUrl = '/product/handle/type/restore'
const initWhere = Object.assign({delete: 'normal'}, route.query)
const opOptions = global.opOptions

const {proxy} = getCurrentInstance() as any
const tdWidth = global.tdWidth
const cateOptions = ref([])
const auth = makeModelAuth('store.goodsTag')

const tabChange = (name: string) => {
    // 添加查询条件
    list.where.delete = name
    list.reload(1)
}

// toolbar 事件
const topToolbar = [
    {
        auth: auth.add,
        type: 'success',
        icon: 'Plus',
        title: '新增',
        event: async (ids:Array<number>) => {
            edit.info = {}
            edit.show = true
        }
    },
    {
        auth: auth.del,
        title: '删除',
        type: 'danger',
        icon: 'Delete',
        event: (ids:any) => {
            list.del({
                url: `/${auth.del}`,
                ids: ids
            })
        }
    },
]

const lineToolbar = [
    {
        auth: auth.edit, title: '编辑', event: (row:any) => {
            edit.info = row
            edit.show = true
        }
    },
    {
        auth: auth.del, title: '删除', type: 'del', event: (row:any) => {
            list.del({
                url: `/${auth.del}`,
                ids: [row.id]
            })
        }
    },
]

const list = reactive(new List({
    where: initWhere,
    url: `/${auth.index}`,
    columns:[
        {name: "select", type:'selection'},
        {name: "id", title:'ID', width:tdWidth.id},
        {name: "title", title:'标签名称', width:tdWidth.min},
        // {name: "status", title: "状态", width: tdWidth.switch, type:"switch", align: "center"},
        {title: "操作", type:'toolbar',toolbar:lineToolbar},
    ]
}))

const edit = reactive(new Edit({}))

const searchRef = ref<FormInstance>()
const search = reactive(new Search({
    list:list,
}))

const exportOut = reactive(new Edit({}))



provide("list", list)
provide("edit", edit)


</script>

<style scoped>

</style>
